import java.util.Arrays;

public class SolutionInterview17_23 {
    public int[] findSquare(int[][] matrix) {
        int m=matrix.length,n=matrix[0].length;
        int[][] sum=new int[m+1][n+1];
        for (int i=1;i<=m;i++){
            for (int j=1;j<=n;j++){
                sum[i][j]=sum[i-1][j]+sum[i][j-1]+matrix[i-1][j-1]-sum[i-1][j-1];
            }
        }
        int max=0,r=-1,c=-1;
        for (int i=0;i<m;i++){
            for (int j=0;j<n;j++){
                if (matrix[i][j]==0){
                    for (int k=0;j+k<n & i+k<m;k++){
                        int a=cal(sum,i,j,i+k,j);
                        int b=cal(sum,i,j,i,j+k);
                        int cc=cal(sum,i,j+k,i+k,j+k);
                        int d=cal(sum,i+k,j,i+k,j+k);
                        if (a!=0 || b!=0 || cc!=0 || d!=0){
                            continue;
                        }
                        if (k+1>max){
                            max=k+1;
                            r=i;
                            c=j;
                        }
                    }
                }
            }
        }
        if (max==0){
            return new int[]{};
        }
        return new int[]{r,c,max};
    }

    private int cal(int[][] sum, int a, int b, int c, int d) {
        return sum[c+1][d+1]-sum[a][d+1]-sum[c+1][b]+sum[a][b];
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new SolutionInterview17_23().findSquare(new int[][]{{1, 0, 1}, {0, 0, 1}, {0, 0, 1}})));
    }
}
